package kuang.stream;

import java.util.Arrays;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        User user1 = new User(1, "A", 11);
        User user2 = new User(2, "B", 22);
        User user3 = new User(3, "C", 33);
        User user4 = new User(4, "D", 44);
        User user5 = new User(5, "E", 66);
        List<User> list = Arrays.asList(user1, user2, user3, user4, user5);

        /**
         * 链式编程、lambda表达式、函数式接口、流式计算
         * filter(Predicate<? super T> predicate); 里面是个断言接口，过滤后的信息
         * map(Function<? super T, ? extends R> mapper); 里面是个正常的函数式接口，进行对象处
         * sorted(Comparator<? super T> comparator); 排序
         * limit(long maxSize) 挑选个数
         * forEach(Consumer<? super T> action) 循环处理
         */
        list.stream()
                .filter(u -> {return u.getId() % 2 == 0;})
                .filter(u -> {return u.getAge() > 23;})
                .map(u -> {return u.getName().toUpperCase();})
                .sorted((u1, u2) -> {return u2.compareTo(u1);})
                .limit(1)
                .forEach(System.out::println);
    }
}
